<template>
<el-card class="class-card">
          <template #header>
            <div class="card-header">
              <span><img width="32" height="32" src="/images/edu/hot-class.png">热门班级</span>
            </div>
          </template>

          <el-row :gutter="20">
            <el-col v-for="(classItem, index) in recommendClasses" :key="index" :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <div class="class-item" @click="viewClassDetail(classItem.id)">
                <div class="class-status" :class="classItem.status">
                  {{ statusText[classItem.status] }}
                </div>
                <el-image :src="classItem.cover" class="class-cover" fit="cover" />
                <div class="class-info">
                  <h4 class="title">{{ classItem.gradeName }}</h4>
                  <p class="course-name">{{ classItem.gradeName }}</p>

                  <div class="meta-info">
                    <div class="meta-item">
                      <el-icon>
                        <Calendar />
                      </el-icon>
                      开班时间：{{ formatDate(classItem.startTime) }}
                    </div>
                    <div class="meta-item">
                      <el-icon>
                        <User />
                      </el-icon>
                      学员：{{ classItem.actualNumber }}/{{ classItem.planNumber }}
                    </div>
                  </div>

                  <div class="progress-container" v-if="classItem.status === 'in-progress'">
                    <el-progress :percentage="classItem.progress" :color="customColors" :show-text="false" />
                    <span class="progress-text">
                      进行中（剩余{{ classItem.remainingDays }}天）
                    </span>
                  </div>

                  <div class="actions">
                    <el-button v-if="classItem.status === 'enrolling'" type="primary" size="small"
                      @click.stop="joinClass(classItem.id)">
                      立即加入
                    </el-button>
                    <el-button v-else-if="classItem.status === 'in-progress'" type="warning" size="small"
                      @click.stop="enterClass(classItem.id)">
                      进入班级
                    </el-button>
                    <el-button v-else type="info" size="small" disabled>
                      已结束
                    </el-button>
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-card>
</template>
<script setup lang="ts">

  const props = defineProps({
    recommendClasses: {
      type: Array,
      required: true
    },
    loading: {
      type: Boolean,
      default: true
    }
  })

  // 格式化方法
const formatDate = (dateStr: string) => {
  console.log('dateStr:', dateStr)
  return new Date(dateStr).toLocaleDateString()
};

// 热门班级数据
const statusText = {
  'enrolling': '报名中',
  'in-progress': '进行中',
  'ended': '已结束'
}
  const viewClassDetail = (id) => {
  console.log('查看班级详情:', id)
}

const joinClass = (id) => {
  console.log('加入班级:', id)
}

const enterClass = (id) => {
  console.log('进入班级:', id)
}
</script>

<style lang="scss" scoped>
// 热门班级 start
.class-card {
    margin-bottom: 20px;
    border-radius: 12px;

    :deep(.el-card__header) {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 16px 24px;
      border-bottom: 1px solid #ebeef5;
    }

    .card-header {
      font-size: 18px;
      font-weight: 600;
      color: #303133;
      img {
        vertical-align: middle;
        margin-right: 8px;
      }
    }

    .class-item {
      position: relative;
      margin-bottom: 20px;
      background: #fff;
      border-radius: 8px;
      overflow: hidden;
      transition: all 0.3s ease;
      cursor: pointer;

      &:hover {
        transform: translateY(-3px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      }

      .class-status {
        position: absolute;
        top: 10px;
        right: -30px;
        width: 100px;
        padding: 4px 0;
        text-align: center;
        background: #409EFF;
        color: white;
        font-size: 12px;
        transform: rotate(45deg);
        z-index: 1;

        &.enrolling {
          background: #67C23A;
        }

        &.in-progress {
          background: #E6A23C;
        }

        &.ended {
          background: #909399;
        }
      }

      .class-cover {
        width: 100%;
        height: 180px;
        border-radius: 8px 8px 0 0;
      }

      .class-info {
        padding: 16px;

        .title {
          font-size: 16px;
          color: #303133;
          margin-bottom: 8px;
          line-height: 1.4;
        }

        .course-name {
          font-size: 12px;
          color: #909399;
          margin-bottom: 12px;
        }

        .meta-info {
          margin-bottom: 12px;

          .meta-item {
            display: flex;
            align-items: center;
            font-size: 12px;
            color: #606266;
            margin-bottom: 8px;

            .el-icon {
              margin-right: 6px;
              font-size: 14px;
            }
          }
        }

        .progress-container {
          margin-bottom: 12px;

          .el-progress {
            margin-bottom: 4px;
          }

          .progress-text {
            font-size: 12px;
            color: #E6A23C;
            float: right;
          }
        }

        .actions {
          text-align: center;

          .el-button {
            width: 100%;
            margin: 0;
          }
        }
      }
    }
  }

  // 热门班级 end
</style>